
new Vue({
    el: "#app",
    data: {
        school: [
            {
                id: "004",
                name: "熔.岩甲兽",
                classType: "土",
                classname: "体质",
            },
            {
                id: "003",
                name: "冰.花刺兽",
                classType: "木",
                classname: "敏捷",
            },
            {
                id: "002",
                name: "噩梦.幽梦兽",
                classType: "暗",
                classname: "攻击",
            },
            {
                id: "001",
                name: "钢.雷顿兽",
                classType: "暗",
                classname: "防御",
            },
        ],
        isflag: false,
        tanindex: -1
    },
    methods: {
        //升序排列
        sheng() {
            this.school.sort((a, b) => {
                return a.id - b.id;
            })
        },
        //降序排列
        jiang() {
            this.school.sort((a, b) => {
                return b.id - a.id;
            })
        },
        //删除
        remove(index) {
            this.school.splice(index, 1);
        },
        //添加
        add() {
            let num1 = uid.value.replace(/[^\d]/g, '');
            if (num1.length == 1) {
                num1 = "00" + num1
            } else if (num1.length == 2) {
                num1 = "0" + num1
            }
            let jihe = {
                id: num1,
                name: uname.value,
                classType: classType.value,
                classname: classname.value
            }
            this.school.push(jihe)
        },
        //编辑
        bianji(index) {
            this.isflag = true;
            let jihe = this.school[index];
            uid1.value = "DS-" + jihe.id;
            uname1.value = jihe.name;
            classType1.value = jihe.classType;
            classname1.value = jihe.classname;
            this.tanindex = index;
            let del=document.getElementsByClassName("del");
            for(let i=0;i<del.length;i++){
                del[i].disabled=true;
            }
        },
        //编辑弹框取消按钮
        quxiao() {
            this.isflag = false;
        },
        //编辑弹框保存按钮
        baochun() {
            let num1 = uid1.value.replace(/[^\d]/g, '');
            if (num1.length == 1) {
                num1 = "00" + num1
            } else if (num1.length == 2) {
                num1 = "0" + num1
            }
            let jihe = {
                id: num1,
                name: uname1.value,
                classType: classType1.value,
                classname: classname1.value
            }
            this.school.splice(this.tanindex, 1, jihe);
            this.isflag = false;
            let del=document.getElementsByClassName("del");
            for(let i=0;i<del.length;i++){
                del[i].disabled=false;
            }
        }
    },
})